import libtcodpy as libtcod
from random import randrange, sample

#===============================================================================
# CONSTANTS
#===============================================================================
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
TARGET_FPS = 15
WINDOW_TITLE = 'Python Test'

CHARS = {
         'player': '@',
         
         'wall': libtcod.CHAR_BLOCK2,
         'floor': '.',
         'door': '+',
         'stairs_up': '<',
         'stairs_down': '>',
         
         'gold': '$',
         'weapon': libtcod.CHAR_ARROW_N,
         'shield': libtcod.CHAR_RADIO_SET,
         'ring': 'o',
         'unknown': '?'
         }

COLORS = {
          'FCOL': libtcod.white,
          'BCOL': libtcod.black,
          
          'wall': [libtcod.light_gray, libtcod.black],
          'floor': [libtcod.white, libtcod.black],
          'door': [libtcod.dark_yellow, libtcod.black],
          
          'player': [libtcod.dark_green, libtcod.black],
          'path': libtcod.light_sky,
          
          'stairs': [libtcod.desaturated_red, libtcod.black],
          'items': [libtcod.yellow, libtcod.black]
          }

FILES = {
         'settings': 'cfgs/settings.cfg',
         'monsters': 'cfgs/monsters.cfg',
         'items': 'cfgs/items.cfg',
         'errors': 'ERRORS.log',
         }

#RECT = [x,y,width,height]
HUD_RECT = [0, 0, 15, SCREEN_HEIGHT]
MAP_RECT = [15, 1, SCREEN_WIDTH - 15, SCREEN_HEIGHT - 1]

MIN_OBJECTS = 2

ACTION_KEYS = 'zyxwvutsrqponmlkjihgfedcba'

FOV_RADIUS = 18
FOV_ALGO = 2 #libtcod.FOV_SHADOW
FOV_DARK = 0.5

#===============================================================================
# USEFUL METHODS
#===============================================================================
def inside_map(x, y):
    if x + MAP_RECT[0] >= MAP_RECT[0] and y + MAP_RECT[1] >= MAP_RECT[1] and x + MAP_RECT[0] < MAP_RECT[0] + MAP_RECT[2] and y + MAP_RECT[1] < MAP_RECT[1] + MAP_RECT[3]:
        return True
    return False

def clamp(val, min, max):
    if val < min:
        return min
    elif val > max:
        return max
    else:
        return val
    
def roll_dice(num = 1, sides = 6, mod = 0):
    if sides <= 0 or num <= 0:
        return 0
    return sum(randrange(sides) + 1 for _ in range(num)) + mod

def scramble_word(word):
    return ''.join(sample(word, len(word)))

#===============================================================================
# ERROR LOGGING
#===============================================================================
def write_error(str):
    f = open(FILES['errors'], 'a')
    f.write(str + '\n')
    f.close()

if __name__ == "__main__":
    print "Please run main.py!"
